package com.jinbo.footmessage.utils;

import android.content.Context;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;

import com.jinbo.footmessage.R;


/**
 * Created by xuzhifan on 2015/8/26.
 */
public class HighLightTextUtil {
    public static SpannableStringBuilder highlightText(Context context, String text, String keyWord){
        ForegroundColorSpan span = new ForegroundColorSpan(context.getResources().getColor(R.color.font_red_cc2200));//要显示的颜色
        SpannableStringBuilder builder = new SpannableStringBuilder(text);
        int index = text.indexOf(keyWord);
        if(index!=-1){
            builder.setSpan(span,index,index+keyWord.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return builder;
    }
}
